package com.reger.canal.client;

import java.net.InetSocketAddress;
import java.net.SocketAddress;

import org.springframework.context.annotation.Bean;

import com.alibaba.otter.canal.client.CanalConnector;
import com.alibaba.otter.canal.client.CanalConnectors;
import com.alibaba.otter.canal.common.utils.AddressUtils;
import com.reger.canal.core.DefaultMessageProcess;

public class CanalClientConfiguration {
	@Bean
	public CanalConnector singleConnector() {
		SocketAddress address = new InetSocketAddress(AddressUtils.getHostIp(), 11111);
		return CanalConnectors.newSingleConnector(address, destination, "", "");
	}

	public String destination = "example";

	
	@Bean
	public MessageProcess process() {
		return new DefaultMessageProcess();
	}
	
	@Bean(initMethod="start",destroyMethod="stop")
	public Client canalClient(CanalConnector connector,MessageProcess process) {
		CanalClient client = new CanalClient();
		client.setConnector(connector);
		client.setProcess(process);
		client.setDestination(destination);
		return client;
	}
}
